﻿package Classes.Weapons{
	import flash.display.*;
	import flash.events.*;
	
	
	import Classes.*;
	import Classes.Utils.*;
	import Classes.Interface.*;
	import Classes.Layers.*;
	import Classes.Elements.*;
	import Classes.Interface.*;

	public class Weapon extends Element{
		public var aTargets:Array;
		public var sender:Element;
		protected var hittestable:Boolean;
		protected var crtspeed:Number;			
		
		public function Weapon(){
			crtspeed = 0;
			execution = 1;
			hittestable = true;
			speed = 0;			
			//用弱引用的方式添加事件侦听器
			addEventListener(Event.ENTER_FRAME,onEnterFrame,false,0,true);
		}
		override protected function onEnterFrame(e:Event):void{
			if(isInRange()){
				move();
				hitTest();
			}
		}
		
		protected function hitTest():void{
			if(!hittestable)
				return;
			for(var i:int = 0;i<aTargets.length;i++){
				var t:Element = aTargets[i] as Element;
				if(HitTest.hitTestPoint(this,t)){
					hittestable = false;
					if(t.hurtable){
						t.killer = this.sender as Element;
						t.hp -= this.execution;
					}
					this.sender = null;
					this.killer = t;
					this.killer.score += this.score;
					this.explodeable = true;
					this.erasable = true;
				}
			}
		}
	}
}